#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

# 文件路径
original_file = r'c:\Users\thomas\Desktop\头哥\前端开发框架知识图谱.csv'
fixed_file = r'c:\Users\thomas\Desktop\头哥\前端开发框架知识图谱_修复版.csv'

# 读取原文件
with open(original_file, 'r', encoding='utf-8') as f:
    content = f.read()

# 添加表头
header = '节点名称,节点类型,父节点,根节点,节点描述,资源来源,资源链接,节点标签,前置节点,关联节点\n'
new_content = header + content

# 写入新文件，使用UTF-8 BOM编码
with open(fixed_file, 'w', encoding='utf-8-sig') as f:
    f.write(new_content)

print(f'CSV文件已修复，保存为: {fixed_file}')
print('现在可以用Excel正常打开了！')
print('\n修复说明：')
print('1. 添加了CSV表头行')
print('2. 使用UTF-8 BOM编码保存，Excel可以正确识别中文字符')
print('3. 请使用修复版文件在Excel中打开')